package com.example.demo.service;

import java.util.List;
import java.util.Random;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import com.example.demo.bean.CmsMember;
import com.example.demo.mapper.CmsMemberMapper;

@Service
public class CmsMemberService {
	
	@Autowired
	private CmsMemberMapper cmsMemberMapper;
	
	public List<CmsMember> selectAll() {
		return cmsMemberMapper.selectAll();	
	}
	
	
	public CmsMember selectById(String id) {
		return cmsMemberMapper.selectByPrimaryKey(id);
	}
	
	public int deleteById(String id) {
		CmsMember csCmsMember= cmsMemberMapper.selectByPrimaryKey(id);
		if (csCmsMember!=null) {
			return cmsMemberMapper.deleteByPrimaryKey(id);
		}
		return -1;
	}
	
	public int batchDeleteByIds(String[] ids)
	{
		if (ids!=null && ids.length>0) {
			return cmsMemberMapper.batchDeleteByIds(ids);
		}
		return 0;
	}
	

	public int saveOrUpdate(CmsMember cmsMember) {
		if (cmsMember.getId() !=null) {
			CmsMember cms= cmsMemberMapper.selectByPrimaryKey(cmsMember.getId());
			if (cms==null) {
				return -1;
			}
			cmsMemberMapper.updateByPrimaryKey(cmsMember);
			return 1;
		}
		else {
			cmsMember.setId(UUID.randomUUID().toString());
			cmsMemberMapper.insert(cmsMember);
		}
		return 1;
	}
}





